﻿using System;
using System.Collections.Generic;
using SimpleServiceBus.Bus;
using SimpleServiceBus.Bus.MessageManagement.Callbacks;
using SimpleServiceBus.Utilities.ObjectBuilder;

namespace SimpleServiceBus.Tests.Stubs
{
    public class TestBus : MessageBus
    {
        public List<SentMessage> PublishedMessages = new List<SentMessage>();
        public List<SentMessage> SentMessages = new List<SentMessage>();

        public SentMessage LastPublished { get; set; }
        public SentMessage LastSent { get; set; }

        public IObjectBuilder ObjectBuilder { get; set; }

        #region IMessageBus Members

       

        public override void Publish(object message)
        {
            LastPublished = new SentMessage(null, message);
            PublishedMessages.Add(LastPublished);
        }

        public override ICallback Send(object message)
        {
            return Send(message, String.Empty);
        }

        public override ICallback Send(object message, string[] destinations)
        {
            LastSent = new SentMessage(destinations[0], message);
            SentMessages.Add(LastSent);
            return null;
        }

        #endregion

  

        public void ReceiveMessage(object message)
        {
            HandleMessage(new MessageEnvelope {Body = message});
        }
    }

    public class SentMessage
    {
        public SentMessage(string to, object message)
        {
            To = to;
            Message = message;
        }

        public string To { get; set; }
        public object Message { get; set; }
    }
   
}